package cn.dglydrpy.study.spring.ioc.factorybean;

import org.springframework.beans.factory.FactoryBean;

/**
 * @Description:  
 * @author:LY_飘涯
 * @date:2021-7-3 22:59:04 
 * @version:1.0
 */
public class CompanyFactoryBean implements FactoryBean<Company> {
	
	private String companyInfo; // 公司名称,地址,规模
	public void setCompanyInfo(String companyInfo) {
		this.companyInfo = companyInfo;
	}

	@Override
	public Company getObject() throws Exception {
		Company company = new Company();
		String[] strings = companyInfo.split(",");
		company.setName(strings[0]);
		company.setAddress(strings[1]);
		company.setScale(Integer.parseInt(strings[2]));
		return company;
	}

	@Override
	public Class<?> getObjectType() {
		return Company.class;
	}

	// 默认单例

	@Override
	public String toString() {
		return "CompanyFactoryBean [companyInfo=" + companyInfo + "]";
	}
}
